<template>
    <div>
        <h2 class="h2"><span>其他信息表--退役士兵</span></h2>
        <div>
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="140px" class="demo-ruleForm qita" id="qita" accept-charset="UTF-8">
                <el-row :gutter="20">
                    <el-col :span="12">
                         <el-form-item class="select2" label="退役安置方式：" prop="E001">
                            <el-select v-model="ruleForm.E001" placeholder="退役安置方式">
                                <el-option label="安排工作" value="安排工作"></el-option>
                                <el-option label="自主就业" value="自主就业"></el-option>
                                <el-option label="自谋职业" value="自谋职业"></el-option>
                            </el-select>               
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="安置日期：" prop="E004">
                            <el-date-picker v-model="ruleForm.E004" type="date" placeholder="安置日期"></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20" class="sanjiliandong">
                    <el-form-item label="安置地点：">
                        <linkage @hujisuozaidifn="hujisuozaidifnsss"></linkage>
                    </el-form-item>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="12">
                         <el-form-item class="select2" label="安置单位性质：" prop="E005">
                            <el-select v-model="ruleForm.E005" placeholder="安置单位性质">
                                <el-option label="行政机关" value="行政机关"></el-option>
                                <el-option label="事业单位" value="事业单位"></el-option>
                                <el-option label="企业" value="企业"></el-option>
                                <el-option label="其他" value="其他"></el-option>
                            </el-select>               
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="安置单位名称：" prop="E006">
                            <el-input v-model="ruleForm.E006" id="E006" placeholder="请输入安置单位名称"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="12">
                         <el-form-item label="参加政府组织的教育培训状况：" prop="E008">
                            <el-radio-group v-model="ruleForm.E008">
                                <el-radio label="是"></el-radio>
                                <el-radio label="否"></el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-form-item>
                        <el-button type="primary" @click="fallbackFn()">上一步</el-button>
                        <el-button type="primary" @click="submitForm('ruleForm')">下一步</el-button>
                        <el-button @click="resetForm('ruleForm')">重置</el-button>
                    </el-form-item>
                </el-row>
            </el-form>
        </div>
    </div>
</template>

<script>
import linkage from '@/components/element/linkage'
import interface_s from '@/api/api.js'
export default {
    data(){
        return {
            ruleForm: { //默认数据
                E001:'', //退役安置方式
                E002:'',
                E003:'',//安置地点
                E004:'', //安置日期
                E005:'',//安置单位性质
                E006:'',//请输入安置单位名称
                E007:'',
                E008:'',//参加政府组织的教育培训状况
                E009:'',E010:'',E011:'',E012:'',E013:'',E014:'',E015:'', E016:'',E017:'',
                E018:'',E019:'',E020:'',E021:'',E022:'',E023:'',E024:'',E025:'',E026:'',
                E027:'',E028:'',E029:'',E030:'',E031:'',E032:'',E033:'',E034:'',
                userID:this.$cookies.get('userID'),
            },
            rules: {  //规则
                E004:[
                    { type: 'string', required: true, message: '请选择入伍时间', trigger: 'change' }
                ],
                E001:[
                    { required: true, message: '请选择退役安置方式', trigger: 'change' },
                ],
                E005:[
                    { required: true, message: '请选择安置单位性质', trigger: 'change' },
                ],
                E006:[
                    { required: true, message: '请输入安置单位名称', trigger: 'blur' },
                ],
                E008:[
                    { required: true, message: '请选择参加政府组织的教育培训状况', trigger: 'change' },
                ],
            },
        }
    },
    methods: {
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    // alert('成功，tuiyishibing!');
                    console.log(this.ruleForm)

                    let postData = this.$qs.stringify(this.ruleForm);
                    console.log(postData)
                    // 基本信息提交
                    this.$axios.post(this.HOST+interface_s.qita,postData,{
                        headers:{
                            'Content-Type':'application/x-www-form-urlencoded', 
                        }
                    })
                    .then( (response) => {
                        if(response.data.code==0){
                            this.$alert('填写成功！', '消息', {
                                confirmButtonText: '确定',
                                callback: action => {
                                    // this.$emit('submitfn',5)
                                    this.$router.push('/')
                                }
                            })
                        }else{
                            this.$alert('信息填写错误或网络错误', '消息', {
                                confirmButtonText: '确定',
                                callback: action => {
                                   
                                }
                            })
                        }
                        console.log(response);
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
        hujisuozaidifnsss(value){
            this.ruleForm.E003 = value.join(","); 
            console.log(this.ruleForm.E003 )
        },
        fallbackFn(){
            this.$confirm('您确定返回上一层吗？如果反回此处得重新填写', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$emit('submitfn',4)
            }).catch(() => {
                //取消
            });
        }
    },
    components:{
        linkage
    },
    created(){
        let datas = JSON.parse(sessionStorage.getItem('data'));
        if(datas){
            this.ruleForm.E001 = datas.e001
            this.ruleForm.E003 = datas.e003
            this.ruleForm.E004 = datas.e004
            this.ruleForm.E005 = datas.e005
            this.ruleForm.E006 = datas.e006
            this.ruleForm.E008 = datas.e008
        }
    }
}
</script>

<style scoped>
.el-row {
    margin-bottom: 20px;
}
.el-row:last-child {
    margin-bottom: 0;
}
</style>